<?php
/**
 * Created by PhpStorm.
 * User: zyh
 * Date: 2018/5/25
 * Time: 下午11:39
 */

namespace app\admin\controller;



use app\admin\model\Rewards;
use GatewayClient\Gateway;
use think\Cache;
use think\Controller;

class Game extends Base
{

    public function game_source()
    {
        $game = new \app\admin\model\Game();
        $games = $game->all();
        return ['status'=>1,"data"=>$games];
    }

    public function game_list()
    {
        return view();
    }

//    开始游戏 新建游戏ID
    public function newgame()
    {
        $game = new \app\admin\model\Game();
        if ($post = input("post.")){
            $id = input("post.id");
            $start_time = input("post.start_time");

            $id = $game->save(['id'=>$id,'start_time'=>$start_time]);
            Gateway::sendToGroup("user",'{"type":"refresh"}');
            return ['status'=>1,'id'=>$game->getLastInsID()];
        }
        $id = $game->field('id')->order('id','desc')->find();
        $this->assign("id",$id['id']?$id['id']+1:100000);
        $this->assign("start_time",date("Y-m-d H:i:s"));
        return view();

    }

//    开始游戏详情  重点
    public function game_start()
    {
        $id = input()['id'];
        $this->assign("game_id",$id);
        return view();
    }

    public function test()
    {
        $r = new Rewards();
        $r->settlement(100000,10,1);
        //让红方胜利
    }

    public function test1()
    {
        Cache::set("kou",2);
    }
}